<?php
include "db.php";
$username = $_POST["username"] ?? "";
$password = $_POST["password"] ?? "";

if ($username =="" ||  $password =="" ){
    die("用户名和密码不能为空");
}

$sql = "select * from user where username = '{$username}'";
$user = $db->read($sql)[0];
if($user == false){
    die("用户不存在");
}
if (!password_verify($password,$user["password"])){
    die("密码错误");
}


if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}
$_SESSION["id"] = $user["id"];
header("refresh:1;url=bootstrap.php");
echo "登录成功,1秒后自动跳转到首页";
?>